package com.njym.java.security.app.rest;


import com.github.pagehelper.PageInfo;
import com.njym.java.security.app.biz.GroupsMsgContentBiz;
import com.njym.java.security.app.entity.GroupsMsgContent;
import com.njym.java.security.app.entity.UserMessage;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("groupsMsgContent")
public class GroupsMsgContentController extends BaseController<GroupsMsgContentBiz,GroupsMsgContent> {
    @RequestMapping(value = "/queryGroupHistory",method = RequestMethod.GET)
    @ResponseBody
    public Object queryGroupHistory(String groupId,
        @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1")int page){
        if (!groupId.equals("undefined")) {
            List<GroupsMsgContent> list = baseBiz.queryGroupHistory(Integer.parseInt(groupId), page, limit);
            long total = PageInfo.of(list).getTotal();
            Map<String, Object> data = new HashMap<>(2);
            data.put("list", list);
            data.put("totalPages", total);
            return new ObjectRestResponse<UserMessage>().rel(true).data(data);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }


    }
}